home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / microcrn / issue_46.arc / ISR.ARC / CALLER.C < prev    next >
Encoding:
Text File  |  1988-05-11  |  1.7 KB  |  127 lines

  1. /*    CALLER.c -  Routine to do Far Calls.
  2.  
  3.         Supports ISR article in Micro Cornucopia Magazine Issue #46
  4. */
  5.  
  6.  
  7. #asm
  8.  
  9. codeseg    segment    para public 'code'
  10.  
  11.     public  _AX_,_BX_,_CX_,_DX_
  12.     public  _AL_,_AH_,_BL_,_BH_,_CL_,_CH_,_DL_,_DH_
  13.     public  _SI_,_DI_,_BP_
  14.     public  _ESBX_, _DSDX_, _DXAX_, _BPSI_
  15.     public  _DS_,_ES_
  16.     public  _PC_,_IP_,_CS_
  17.     public  _PSW_
  18.     public  _STKPTR_,_SP_,_SS_
  19.  
  20. _ESBX_    label   dword
  21. _BX_    label   word
  22. _BL_    db      ?
  23. _BH_    db      ?
  24.  
  25. _ES_    dw      ?
  26.  
  27. _CX_    label   word
  28. _CL_    db      ?
  29. _CH_    db      ?
  30.  
  31. _DXAX_    label   dword
  32. _AX_    label   word
  33. _AL_    db      ?
  34. _AH_    db      ?
  35.  
  36. _DSDX_    label   dword
  37. _DX_    label   word
  38. _DL_    db      ?
  39. _DH_    db      ?
  40.  
  41. _DS_    dw      ?
  42.  
  43. _DI_    dw      ?
  44.  
  45. _BPSI_    label   dword
  46. _SI_    dw      ?
  47. _BP_    dw      ?
  48.  
  49. _PC_    label   dword
  50. _IP_    dw      ?
  51. _CS_    dw      ?
  52.  
  53. _PSW_    dw      ?
  54.  
  55. _STKPTR_ label  dword
  56. _SP_    dw      ?
  57. _SS_    dw      ?
  58.  
  59. sav_ss    dw    ?
  60. sav_sp    dw    ?
  61.  
  62. codeseg    ends
  63.  
  64. #endasm
  65.  
  66. #pragma vpindex caller
  67. unsigned int far caller() /* returns CPU FLAGS */
  68. {
  69. #asm
  70.     push    bx        ;save the callers regs
  71.     push    cx
  72.     push    si
  73.     push    di
  74.     push    bp
  75.     push    ds
  76.     push    es
  77.  
  78.     mov    sav_ss, ss
  79.     mov    sav_sp, sp
  80.  
  81.     mov    ds, _DS_
  82.     mov    es, _ES_
  83.  
  84.     mov    ax, _AX_
  85.     mov    bx, _BX_
  86.     mov    cx, _CX_
  87.     mov    dx, _DX_
  88.  
  89.     mov    si, _SI_
  90.     mov    di, _DI_
  91.     mov    bp, _BP_
  92.  
  93.     pushf            ;in case we're faking an interrupt
  94.     call    dword ptr _PC_
  95.  
  96.     mov    _AX_, ax
  97.     mov    _BX_, bx
  98.     mov    _CX_, cx
  99.     mov    _DX_, dx
  100.  
  101.     mov    _SI_, si
  102.     mov    _DI_, di
  103.     mov    _BP_, bp
  104.     mov    _DS_, ds
  105.     mov    _ES_, es
  106.     mov    _SP_, sp
  107.     mov    _SS_, ss
  108.  
  109.     pushf
  110.     pop    ax
  111.     mov    _PSW_, ax
  112.  
  113.     mov    ss, sav_ss
  114.     mov    sp, sav_sp
  115.  
  116.     pop    es
  117.     pop    ds
  118.     pop    bp
  119.     pop    di
  120.     pop    si
  121.     pop    cx
  122.     pop    bx
  123. #endasm
  124. }
  125.  
  126.  
  127.